package com.ease.access.workbench.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.ease.access.workbench.service.CoolActionAccessService;
import com.ease.access.workbench.service.CoolButtonAccessService;
import com.ease.common.vo.Ordering;
import com.ease.model.term.CoolAction;
import com.ease.model.term.CoolButton;
import com.ease.platform.access.service.impl.AbstractParameterizedBeanIbatisAccessServiceImpl;
import com.obas.platform.workbench.util.ActionParameterStructureUtil;

public class CoolButtonAccessServiceImpl extends AbstractParameterizedBeanIbatisAccessServiceImpl<CoolButton> implements CoolButtonAccessService {

	@Autowired
	private CoolActionAccessService coolActionAccessService;

	@Override
	public List<CoolButton> findByCoolbarId(long coolbarId) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("toolbarId", String.valueOf(coolbarId));
		// List<CoolButton> result =
		// this.getIbatisDataAccessObject().getSqlMapClientTemplate().queryForList("CoolButton.findByToolbarIdRecursion",
		// map);
		List<CoolButton> result = this.find("findByToolbarIdRecursion", parameter, (Ordering) null);
		if (null != result) {
			for (CoolButton coolButton : result) {
				if (coolButton.getActionId() > 0) {
					CoolAction action = coolActionAccessService.findById(coolButton.getActionId());
					coolButton.setAction(action);
					Map<String, Object> parameterMap = new HashMap<String, Object>();
					coolButton.setParameterMap(ActionParameterStructureUtil.generateParameterMap(action.getParameter(), parameterMap));
				}
			}
		}
		return result;
	}

	/**
	 * @return the coolActionAccessService
	 */
	public CoolActionAccessService getCoolActionAccessService() {
		return coolActionAccessService;
	}

	/**
	 * @param coolActionAccessService
	 *            the coolActionAccessService to set
	 */
	public void setCoolActionAccessService(CoolActionAccessService coolActionAccessService) {
		this.coolActionAccessService = coolActionAccessService;
	}

}
